/*
 * @Author: your name
 * @Date: 2021-10-21 16:56:30
 * @LastEditTime: 2021-10-26 15:53:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \X\1km\driver\sensor\encode\enc_brt_can.h
 */
#ifndef _ENC_BRT_CAN_H_
#define _ENC_BRT_CAN_H_

#include "../../bsp/bsp.h"

#define OFFLINE_TIME_MS         1000
#define ENC_BRT_CAN_MAX_CNT     (1024 << 16)        //单圈绝对1024,多圈65536

#define ENCODE_JITTER_RANGE     20                  //编码器在机械结构上可允许的抖动范围(编码器本身线性度0.1%,可忽略,主要考虑结构振动带来的抖动)
#define MAX_SPEED_MM_PER_S      200                 //最大速度 200mm/s
#define MAX_DISTANCE(i)         (((aos_now_ms() - EncTable[i].updateTime) / 1000.0f * (MAX_SPEED_MM_PER_S)) / EncTable[i].transRatio + ENCODE_JITTER_RANGE)
#define MAX_ALLOW_RANGE(i)      MAX_DISTANCE(i)     //两次更新期间最大允许变化量
//#define MAX_ALLOW_RANGE(i)    100                 //经验值

#define CMD_GET_SING_COUNT      0x01
#define CMD_SET_ENC_ID          0x02
#define CMD_SET_ENC_BAUD        0x03
#define CMD_SET_ENC_MODE        0x04
#define CMD_SET_RSP_TIME        0x05
#define CMD_SET_ENC_ZERO        0x06
#define CMD_SET_ENC_DIRECT      0x07
#define CMD_GET_MULT_COUNT      0x08
#define CMD_GET_MULT_NUMS       0x09
#define CMD_GET_ANGLE_SPEED     0x0A
#define CMD_SET_SAMPLING_TIME   0x0B


//初始化所有编码器,但凡有一个初始化失败将返回false,并且不会创建任务
extern bool xp_enc_brt_can_init(void);

//根据编号查询编码器是否离线(默认宏设置1s的离线检测时间)
extern bool xp_enc_brt_can_isOffline(uint8_t index);
//根据编号查询编码器读取失败率
extern bool xp_enc_brt_can_get_failRate(uint8_t index, float *pResult);
//根据编号清空编码器读取回应统计
extern bool xp_enc_brt_can_clear_failRate(uint8_t index);
//根据编号查询编码器位置(经过变换比例之后的值)
extern bool xp_enc_brt_can_get_pos(uint8_t index, int32_t *pResult);
//根据编号设置编码器当前位置为零点
extern bool xp_enc_brt_can_set_zero(uint8_t index);


#endif